﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.ZhaoLuService;

namespace CommunitySystem
{
    public partial class ZhaoLuJiHuaControl : UserControl
    {
        private ZhaoLuServiceClient Client = new ZhaoLuServiceClient();
        public ZhaoLuJiHuaControl()
        {
            InitializeComponent();
            for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Content = i.ToString();
                cbi.Tag = i;
                nian.Items.Add(cbi);
            }
            nian.SelectedIndex = 0;
            Load();
        }

        public void Load()
        {
            Client.GetZhaoLuJiHuaModelCompleted -= new EventHandler<GetZhaoLuJiHuaModelCompletedEventArgs>(Client_GetZhaoLuJiHuaModelCompleted);
            Client.GetZhaoLuJiHuaModelCompleted += new EventHandler<GetZhaoLuJiHuaModelCompletedEventArgs>(Client_GetZhaoLuJiHuaModelCompleted);
            Client.GetZhaoLuJiHuaModelAsync(DateTime.Today.Year - nian.SelectedIndex, islock);
        }

        void Client_GetZhaoLuJiHuaModelCompleted(object sender, GetZhaoLuJiHuaModelCompletedEventArgs e)
        {
            DGRole.ItemsSource = e.Result;
        }

        private string islock = "0";
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            islock = "1";
        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            islock = "0";
        }

        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            //if (orgids.Count > 1)
            //{
            //    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能针对一个单位进行职位信息的新增！");
            //    return;
            //}
            ZhaoLuJiHuaTitleWindow RMWindow = new ZhaoLuJiHuaTitleWindow(DateTime.Today.Year - nian.SelectedIndex);
            RMWindow.Closed += new EventHandler(RMWindow_Closed);
            RMWindow.Show();
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            Load();
        }

        private void EditData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as ZhaoLuJiHuaModel;

            //throw new NotImplementedException();
            if (seljw != null)
            {
                ZhaoLuJiHuaWindow RMWindow = new ZhaoLuJiHuaWindow(seljw.ID, seljw.ID, DateTime.Today.Year - nian.SelectedIndex, seljw.Name, false);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的计划！");
        }

        private void DeleteData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as ZhaoLuJiHuaModel;
            if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Client.DeleteZhaoLuJiHuaCompleted -= new EventHandler<DeleteZhaoLuJiHuaCompletedEventArgs>(Client_DeleteZhaoLuJiHuaCompleted);
                Client.DeleteZhaoLuJiHuaCompleted += new EventHandler<DeleteZhaoLuJiHuaCompletedEventArgs>(Client_DeleteZhaoLuJiHuaCompleted);
                Client.DeleteZhaoLuJiHuaAsync(seljw.ID);
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要删除的计划！");
        }

        void Client_DeleteZhaoLuJiHuaCompleted(object sender, DeleteZhaoLuJiHuaCompletedEventArgs e)
        {
            Load();
        }

        private void ViewData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as ZhaoLuJiHuaModel;

            //throw new NotImplementedException();
            if (seljw != null)
            {
                ZhaoLuJiHuaWindow RMWindow = new ZhaoLuJiHuaWindow(seljw.ID, seljw.ID, DateTime.Today.Year - nian.SelectedIndex, seljw.Name, true);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的计划！");
        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }

        private void dgXQ_LoadingRow(object sender, DataGridRowEventArgs e)
        {
        }

        private void DaoChuData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as ZhaoLuJiHuaModel;

            //throw new NotImplementedException();
            if (seljw != null)
            {
                

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的计划！");
        }
    }
}
